home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 August / PCpro_2005_08.ISO / files / freeware / autohot / AutoHotkeyInstall.exe / Extras / Run this to install syntax highlighting for UltraEdit.ahk < prev    next >
Encoding:
Text File  |  2005-04-30  |  8.8 KB  |  246 lines

  1. ;##############################################################################
  2. ;#
  3. ;#  Add or update syntax higlighting for AutoHotKey scripts in UltraEdit
  4. ;#
  5. ;#  Mod of a script done by Tekl (although not much has survived)
  6. ;#  Mod done by toralf, 2005-02-15
  7. ;#
  8. ;#  Tested with: AHK 1.0.26.00, Windows XP Pro, UltraEdit 10.10c/10.20
  9. ;#
  10. ;#  Requirements
  11. ;#    - Syntax files for AHK in one directory
  12. ;#    - UltraEdit uses standard file for highlighting => wordfile.txt
  13. ;#
  14. ;#  Customize:
  15. ;#    - The default color for strings is gray, change it to any color
  16. ;#         you want to have "%var%" to appeer => Extra->Option->syntaxhiglighting
  17. ;#    - Change the default color for up to 8 keyword groups
  18. ;#         => Extra->Option->syntaxhiglighting
  19. ;#    -specify up to 8 syntax files, each containing one keywords per line
  20. ;#         => you can add your own files, for keywords that you want to highlight
  21. ;#            Personally I use 3 additional: Operators, Separators and Special
  22. ;#            Operators.txt => "=`n<`n>`n*`n/`n+`n-"
  23. ;#            Separators.txt => "``n`n``r`n|`n,`n{`n}"
  24. ;#            Special.txt => "** x y w h r v g`nis`nnot`nCBlue`ncRed"
  25. ;#
  26.  
  27. ; Specify a list of up to 8 syntax files; the order influences the color given to them by UE by default
  28. SyntaxFileNameList = CommandNames|Keywords|Variables|Keys      ; e.g. add |Operators|Separators|Special
  29. ;Default colors in UE:  blue     |red     |orange   |green    |brown   |blue      |blue    |blue
  30.  
  31. SyntaxExtention = .txt
  32.  
  33. ;#############   END of Customization Area   ##################################
  34.  
  35. ;#############   Ask and Check for valid input  ###############################
  36.  
  37. RegRead, UeditPath, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\UEDIT32.exe,Path
  38. IfNotExist, %UeditPath%\uedit32.exe
  39. {
  40.     UeditPath = %A_ProgramFiles%\UltraEdit
  41.     IfNotExist, %UeditPath%\uedit32.exe
  42.     {
  43.         FileSelectFolder, UeditPath,, 0, Select UltraEdit program-folder
  44.         IfNotExist, %UeditPath%\uedit32.exe
  45.         {
  46.            MsgBox UltraEdit cannot be found.
  47.            ExitApp
  48.         }
  49.     }
  50. }
  51.  
  52. UEini = %APPDATA%\IDMComp\UltraEdit\uedit32.ini
  53. IfNotExist, %UEini%
  54. {
  55.     UEini = %A_WinDir%\uedit32.ini
  56.     IfNotExist, %UEini%
  57.         FileSelectFile, UEini, 1, %A_ProgramFiles%\UltraEdit, Select UltraEdit INI-File, *.ini
  58. }
  59. IniRead, UEwordfile, %UEini%, Settings, Language File
  60. if UEwordfile = ERROR
  61. {
  62.    MsgBox INI-File "%UEini%" is missing the Key "Language File".
  63.    ExitApp
  64. }
  65.  
  66. ;Search or ask for Wordfile, when it doesn't exist -> exit
  67. UEwordfile = %UeditPath%\wordfile.txt
  68. IfNotExist, %UEwordfile%
  69. {
  70.     FileSelectFile, UEwordfile, 1, %A_ProgramFiles%, Select UltraEdit wordfile, *.txt
  71.     IfNotExist, %UEwordfile%
  72.     {
  73.         MsgBox UltraEdit Wordfile cannot be found.
  74.         ExitApp
  75.     }
  76. }
  77.  
  78. ; Search or ask for specified syntax folder and files, when they don't exist -> exit
  79. ; Get path of AHK Installation so that syntax files can be found more reliably:
  80. RegRead, ahkpath, HKEY_LOCAL_MACHINE, SOFTWARE\AutoHotKey, InstallDir
  81. PathSyntaxFiles = %ahkpath%\AutoHotkey\Extras\Editors\Syntax
  82. IfNotExist, %PathSyntaxFiles%
  83. {
  84.     PathSyntaxFiles = %A_ProgramFiles%\AutoHotkey\Extras\Editors\Syntax    
  85.     IfNotExist, %PathSyntaxFiles%
  86.     {
  87.         FileSelectFolder, PathSyntaxFiles, %A_ProgramFiles%,2, Select Folder "AutoHotkey\Extras\Editors\Syntax"
  88.         IfNotExist, %PathSyntaxFiles%
  89.         {
  90.             MsgBox Folder containing syntax files not found.
  91.             ExitApp
  92.         }
  93.     }
  94. }
  95.  
  96. MissingFile =
  97. FileCount = 0
  98. Loop, Parse, SyntaxFileNameList, |
  99. {
  100.     FileCount += 1
  101.     IfNotExist, %PathSyntaxFiles%\%A_LoopField%%SyntaxExtention%
  102.         MissingFile = %MissingFile%`n%A_LoopField%%SyntaxExtention%
  103. }
  104. If MissingFile is not space
  105. {
  106.     MsgBox AHK Syntax file(s)`n%MissingFile%`n`ncannot be found in`n`n%PathSyntaxFiles%\.
  107.     ExitApp
  108. }
  109. If FileCount > 8
  110. {
  111.     MsgBox You have specified %FileCount% Syntax files.`nOnly 8 are supported be UltraEdit.`nPlease shorten the list.
  112.     ExitApp
  113. }
  114.  
  115. ;Check the number of languages in the current wordfile, if more than 19 without AHK -> exit
  116. NumberOfLanguages = 0
  117. Loop, Read, %UEwordfile%
  118. {
  119.     StringLeft, WFdef, A_LoopReadLine, 2
  120.     if WFdef = /L
  121.     {
  122.         StringSplit, WFname, A_LoopReadLine, "
  123.         LanguageName = %WFname2%
  124.         if LanguageName <> AutoHotkey
  125.             NumberOfLanguages += 1
  126.     }
  127. }
  128. If NumberOfLanguages > 19
  129. {
  130.     MsgBox, 48,, The wordfile has %NumberOfLanguages% syntax-schemes. UltraEdit does only support 20 schemes.`nPlease delete schemes from the file!
  131.     ExitApp
  132. }
  133.  
  134. ;#############   Read keywords from syntax files into arrays   ################
  135.  
  136. Loop, Parse, SyntaxFileNameList, |  ;Read all syntax files
  137. {
  138.     SyntaxFileName = %A_LoopField%
  139.     GoSub, ReadSyntaxFromFile       ;SyntaxFileName will become string with keywords
  140. }
  141.  
  142. ;#############   Build language specific highlight for AHK   ##################
  143.  
  144. StrgAHKwf = "AutoHotkey" Nocase
  145. StrgAHKwf = %StrgAHKwf% Line Comment = `;
  146. StrgAHKwf = %StrgAHKwf% Line Comment Preceding Chars = [~``]     ;to escape escaped ;
  147. StrgAHKwf = %StrgAHKwf% Escape Char = ``
  148. StrgAHKwf = %StrgAHKwf% String Chars = `%
  149. StrgAHKwf = %StrgAHKwf% Block Comment On = /*
  150. StrgAHKwf = %StrgAHKwf% Block Comment Off = */
  151. StrgAHKwf = %StrgAHKwf% File Extensions = ahk`n
  152. StrgAHKwf = %StrgAHKwf%/Delimiters = *~`%+-!^&(){}=|\/:"'``;<>%A_Tab%,%A_Space%.`n
  153. StrgAHKwf = %StrgAHKwf%/Indent Strings = "{" ":"`n
  154. StrgAHKwf = %StrgAHKwf%/Unindent Strings = "}" "Return" "Else"`n
  155. StrgAHKwf = %StrgAHKwf%/Function String = "`%^([a-zA-Z0-9#_@$?^[^]]+^):"`n
  156. StrgAHKwf = %StrgAHKwf%/Function String 1 = "`%^([~; ^t^p]*^)`::"`n
  157.  
  158. Loop, Parse, SyntaxFileNameList, |      ;Add the keywords from syntax strings into their sections
  159. {
  160.     StrgAHKwf = %StrgAHKwf%/C%A_Index%"%A_LoopField%"   ;section definition
  161.     SyntaxString = %A_LoopField%             ;which section/syntax
  162.     GoSub, ParseSyntaxString                 ;parse through string and add to list
  163. }
  164.  
  165. ;#############   Add or Update Wordfile   #####################################
  166.  
  167. ;Name of a file for temporary store the word file
  168. TemporaryUEwordFile = TempUEwordFile.txt
  169. FileDelete, %TemporaryUEwordFile%
  170.  
  171. Loop, Read, %UEwordfile%, %TemporaryUEwordFile%   ;Read through Wordfile
  172. {
  173.     StringLeft, WFdef, A_LoopReadLine, 2
  174.     if WFdef = /L
  175.     {
  176.         StringSplit, WFname, A_LoopReadLine, "
  177.         LanguageName = %WFname2%
  178.         LanguageNumber = %WFname1%
  179.         StringTrimLeft,LanguageNumber,LanguageNumber,2
  180.         if LanguageName = AutoHotkey         ;when AHK section found, place new section at same location
  181.         {
  182.             FileAppend, /L%LanguageNumber%%StrgAHKwf%
  183.             AHKLanguageFound := True
  184.         }
  185.     }
  186.     if LanguageName <> AutoHotkey            ;everything that does not belong to AHK, gets unchanged to file
  187.     FileAppend, %A_LoopReadLine%`n
  188. }
  189.  
  190. if not AHKLanguageFound                      ;when AHK section not found, append AHK section
  191. {
  192.     LanguageNumber += 1
  193.     FileAppend, /L%LanguageNumber%%StrgAHKwf%, %TemporaryUEwordFile%
  194. }
  195.  
  196. FileCopy, %UEwordfile%, %UEwordfile%.ahk.bak, 1    ;Create Backup of current wordfile
  197. FileMove, %TemporaryUEwordFile%, %UEwordfile%, 1       ;Replace wordfile with temporary file
  198.  
  199. ; Tell user what has been done
  200. Question = `n`nWould you like to make UltraEdit the default editor for AutoHotkey scripts (.ahk files)?
  201. if AHKLanguageFound
  202.     MsgBox, 4,, The AutoHotkey-Syntax for UltraEdit has been updated in your wordfile:`n`n%UEwordfile%`n`nA backup has been created in the same folder.%Question%
  203. else
  204.     MsgBox, 4,, The AutoHotkey-Syntax for UltraEdit has been added to your wordfile:`n`n%UEwordfile%`n`nA backup has been created in the same folder.%Question%
  205.  
  206. IfMsgBox, Yes
  207.     RegWrite, REG_SZ, HKEY_CLASSES_ROOT, AutoHotkeyScript\Shell\Edit\Command,, %UeditPath%\uedit32.exe "`%1"
  208.  
  209. ExitApp  ; That's it, exit
  210.  
  211. ;#############   SubRoutines   ################################################
  212.  
  213. ReadSyntaxFromFile:
  214. TempString =
  215. Loop, Read , %PathSyntaxFiles%\%SyntaxFileName%%SyntaxExtention%   ;read syntax file
  216. {
  217.     StringLeft,Char, A_LoopReadLine ,1
  218.     ;if line is comment, don't bother, otherwise add keyword to string
  219.     If Char <> `;
  220.     {
  221.         ;only add first word in line
  222.         Loop parse, A_LoopReadLine, `,%A_Tab%%A_Space%
  223.         {
  224.             TempString = %TempString%%A_LoopField%`n
  225.             break
  226.         }
  227.     }
  228. }
  229. %SyntaxFileName% = %TempString%                          ;Assign string to syntax filename
  230. Sort, %SyntaxFileName%, U                                ;Sort keywords in string
  231. return
  232.  
  233. ParseSyntaxString:
  234. Loop, Parse, %SyntaxString%, `n                 ;parse through syntax string
  235. {
  236.     StringLeft, Char, A_LoopField,1
  237.     If (Char = PrevChar)                       ;add keyword to line when first character is same with previous keyword
  238.         StrgAHKwf = %StrgAHKwf% %A_LoopField%
  239.     else                                       ;for every keyword with a new first letter, start a new row
  240.         StrgAHKwf = %StrgAHKwf%`n%A_LoopField%
  241.     PrevChar = %Char%                          ;remember first character of keyword
  242. }
  243. return
  244.  
  245. ;#############   END of File   ################################################
  246.